<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://code.google.com/p/granizo" prefix="granizo"%>
<%@ page import="by.bsuir.entity.Node"%>

<html>
  <head>
    <script type="text/javascript">
    function DPCM(input) {
        var value = input.value;
        var re = /[^0-9]/gi;
        if (re.test(value)) {
            value = value.replace(re, '');
            input.value = value;
    }}

    </script>
    
    <c:url value="/css/jquery.treeview.css" var="url" />
    <link href="${url}" rel="stylesheet" type="text/css" media="screen" />

    <c:url value="/css/screen.css" var="url" />
    <link href="${url}" rel="stylesheet" type="text/css" media="screen" />
     
    <c:url value="/js/jquery.js" var="url" />
    <script src="${url}" type="text/javascript"></script>
     
    <c:url value="/js/jquery.cookie.js" var="url" />
    <script src="${url}" type="text/javascript"></script>
    
    <c:url value="/js/jquery.treeview.js" var="url" />
    <script src="${url}" type="text/javascript"></script>
    
    <c:url value="/js/jquery.treeview.edit.js" var="url" />
    <script src="${url}" type="text/javascript"></script>
    <title>Indexation system</title>
  </head>
  <body>
  <div id="main">
  <h1>Система индексации и поиска открытых ресурсов в локальной сети</h1>
    <form action="scan" method="post">
    <table>
        <tr> 
            <td>Логин:</td>
            <td>Пароль:</td>
            <td>Домен:</td>
         </tr>
         <tr>
            <td><input type="text" name="login" value="${login}"/></td>
            <td><input type="password" name="passwd" value="${passwd}"/></td>
            <td><input type="text" name="domain" value="${domain}"/></td>
         </tr>
         
         <tr> 
            <td>Диапозон (4й байт):</td>
            <td>Хост:</td>
         </tr>
         <tr>
            <td>
            <c:out value="с:"></c:out>
            <input type="text" name="firstIp" size="2" onkeyup="DPCM(this)" value="${firstIp}"/>
            <c:out value="по:"></c:out>
            <input type="text" name="lastIp" size="2" onkeyup="DPCM(this)" value="${lastIp}"/>
            </td>
            <td><input type="text" name="host" value="${host}"/></td>
            <td><input type="submit" value="Сканировать"/></td>
         </tr>
      </table>
      </form>
      <form action="load" method="post">
         <input type="submit" value="Загрузить"/>
          </form>
            <form action="search" method="post">
          <input type="text" name="search" value="${search}"/>
          <input type="submit" value="Поиск"/>
          </form>

    <script type="text/javascript">
      $(function() {
          $("#browser").treeview();
          })
    </script>

    <% Node node = (Node) pageContext.getSession().getAttribute("node"); 
       if (node == null) {
           Node rootNode = new Node();
           rootNode.setName("local");
           pageContext.getSession().setAttribute("node", rootNode);
       }
    %>
    <ul id="browser" class="filetree">
    <c:set var="previousLevel" value="0"/>

    <granizo:tree tree="${node}" connectMethod="getNodes" var="status">
            <granizo:startElement>
                    <c:if test="${previousLevel < status.level}">
                            <ul>
                    </c:if>

                     <c:if test="${status.element.folder}">
                            <li><span class="folder">${status.element.name}</span>
                    </c:if>

                    <c:if test="${status.element.file}">
                            <li><span class="file">${status.element.name}</span>
                    </c:if>

            </granizo:startElement>

            <granizo:endElement>
                    <c:if test="${previousLevel > status.level}">
                            </ul>
                    </c:if>

                    </li>
            </granizo:endElement>

    <c:set var="previousLevel" value="${status.level}"/>
    </granizo:tree>
    </ul>

    </div>
  </body>
</html>